package com.phxz.phxzinterface.controller;

import com.phxz.clientsdk.httpclient.Client.HttpClient;
import com.phxz.clientsdk.httpclient.SignUtils.SignUtil;
import com.phxz.clientsdk.httpclient.model.User;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping()
public class NameController {
    @GetMapping("/name")
    public String getNameByGet(@RequestParam String name){
        return "Get 名字是"+name;
    }
    @PostMapping("/name")
    public String getNameByPost(@RequestBody String name){
        return "Post 名字是"+name;
    }
    @PostMapping("/user")
    public String getName(@RequestBody User user, HttpServletRequest request){
//        String accessKey = request.getHeader("accessKey");
//        String sign = request.getHeader("sign");
//        String nonce = request.getHeader("nonce");
//        String timestamp = request.getHeader("timestamp");
//        String body = request.getHeader("body");
//        if(Integer.parseInt(nonce)>10000){
//            throw new RuntimeException("重复");
//        }
//        if(System.currentTimeMillis()/1000-Long.valueOf(timestamp)>10){
//            throw new RuntimeException("超时失效");
//        }
//        // todo accessKey=>secretKey
//        String serverSign = SignUtil.getSign(body, "20021031");
//        if(!serverSign.equals(sign)){
//            throw new RuntimeException("密码错误");
//        }
        System.out.println("test");
        return "Post 名字是"+user.getName();
    }
}
